home *** CD-ROM | disk | FTP | other *** search
Java Source | 2002-03-28 | 5.0 KB | 144 lines |
- // ------------------------------------------------------------------
- //
- // Purpose.............: PageGenerator
- // Created.............: May 8, 2001
- // Copyright...........: (c) 2001 by Adobe Systems
- //
- // ------------------------------------------------------------------
-
- import java.io.*;
- import java.util.ResourceBundle;
- import java.util.Locale;
-
- /**
- * PageGenerator command line main class.
- * For example:
- * <pre>
- * Usage:
- * PageGenerator urlListFile [savePath [skipFolder [proxyHost [proxyPort]]]]
- * Downloads web pages specified in urlListFile to the folder named by
- * savePath. Uses proxyHost and proxyPort, if specified, as the proxy server
- * for accessing web sites outside your firewall.
- * savePath is the folder in which PageGenerator saves output files:
- * if not specified, it uses PageGenerator's own folder.
- * If skipFolder is specified and numeric, PageGenerator shortens the URL by
- * that many levels (see EXAMPLES).
- * With extension ".txt", urlListFile contains space-delimited pairs of
- * URLs and filenames:
- * http://localhost/magazine/project.asp?RECORD_INDEX=3 project.index3.html
- * With any other extension, urlListFile contains an HTML table, with the URL
- * in the leftmost column, the filename in the rightmost column, and URL
- * arguments specified in the intermediate columns (if any) -- in this case
- * the table's first row contains the URL arguments names.
- * <table> <!-- 2-column version -->
- * <tr><td>http://localhost/magazine/project.asp?RECORD_INDEX[Features]=3</td>
- * <td>project.index3.html</td></tr>
- * </table>
- * or
- * <table> <!-- argument-columns version -->
- * <tr><td>(ignored)</td>
- * <td>RECORD_INDEX[Features]</td> <!-- argument name -->
- * <td>(ignored)</td></tr>
- * <tr><td>http://localhost/magazine/project.asp
- * </td><td>3</td> <!-- argument value -->
- * <td>project.index3.html</td></tr>
- * </table>
- * EXAMPLES
- * java PageGenerator c:\\temp\\urls.txt c:\\temp\\saved-site
- * Reads URLs, saves output files in c:\\temp\\saved\\saved-site (creates
- * folder if necessary).
- * java PageGenerator http://myhost/my-list-page.asp c:\\temp\\saved-site
- * Reads a URLs from HTML dynamically generated by my-list-page.asp.
- * java PageGenerator /tmp/urls.txt /tmp/saved-site
- * UNIX (MacOS X) usage. If filenames contain spaces or other special
- * characters, quote them: "/tmp/My Folder/urls.txt"
- * java PageGenerator /tmp/urls.txt /tmp/saved-site 1
- * As above, but saves URLs like http://myhost/a/b/c.html as
- * /tmp/saved-site/b/c.html, not /tmp/saved-site/a/b/c.html
- * java PageGenerator /tmp/urls.txt /tmp/saved-site 0 myproxy 8080
- * Uses the proxy server http://myproxy:8080 to access URLs.
- * </pre>
- *
- * @author Adobe Systems, Inc.
- * @since 1.0
- */
- public class PageGenerator {
-
- /**
- * Command line main method
- * @param argv Command line parameter
- * @return void
- */
- public static void main(String[] argv) {
- if (argv.length < 1) {
- printUsage();
- }
- String fileName = argv[0];
- String savePath = "";
- int skipFolder = 0;
- String proxyHost = "";
- String proxyPort = "";
-
- if (argv.length >= 2) savePath = argv[1];
- try {
- if (argv.length >= 3) skipFolder = Integer.parseInt(argv[2]);
- } catch(NumberFormatException e ) {
- ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
- System.err.println(rb.getString("error") + rb.getString("specifyNumber4skipFolder"));
- printUsage();
- }
- if (argv.length >= 4) proxyHost = argv[3];
- if (argv.length >= 5) proxyPort = argv[4];
-
- if (savePath.length() > 0) {
- if ((savePath.charAt(0) == '"') && (savePath.charAt(savePath.length()-1) == '"') && (savePath.length() > 3)) {
- savePath += savePath.substring(1,savePath.length()-2); // ex) "f:\a a" => f:\a a
- }
- if (savePath.charAt(savePath.length()-1) != File.separatorChar) {
- savePath += File.separatorChar; // ex) f: => f:\
- }
- }
-
- if (proxyHost.length() > 0) { // proxy setting
- System.getProperties().put( "proxySet", "true" );
- System.getProperties().put( "proxyHost", proxyHost );
- if (proxyPort.length() > 0) {
- System.getProperties().put( "proxyPort", proxyPort );
- }
- }
-
- int downloadedCount = 0;
- try {
- UrlList urlList = new UrlList();
- urlList.readFile(fileName, skipFolder);
-
- UrlReplaceDownload urlReplaceDownload = new UrlReplaceDownload(savePath);
- downloadedCount = urlReplaceDownload.replaceDownload(urlList);
- ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
- print(downloadedCount + rb.getString("filesDownloaded"));
- } catch(Exception e) {
- e.printStackTrace();
- }
- System.exit(downloadedCount);
- }
-
- /**
- * @param void
- * @return void
- */
- static void printUsage() {
- ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
- print(rb.getString("usage"));
- System.exit(-1);
- }
-
- /**
- * @param s Sring to display
- * @return void
- */
- static void print(String s) {
- System.out.println(s);
- }
- }
-
-